package ltype

import (
	"encoding/json"
	"fmt"
	"strconv"
)

func IF2Floa64(value *float64, data interface{}) error {
	switch data.(type) {
	case int:
		*value = float64(data.(int))
	case int8:
		*value = float64(data.(int8))
	case int32:
		*value = float64(data.(int32))
	case int64:
		*value = float64(data.(int64))
	case float32:
		*value = float64(data.(float32))
	case float64:
		*value = data.(float64)
	case string:
		v, err := strconv.ParseFloat(data.(string), 64)
		if err != nil {
			return err
		}
		*value = v
	default:
		err := fmt.Errorf("不支持的数据类型: %T", data)
		return err
	}
	return nil
}

func Json2Map(jsonData string) (map[string]interface{}, error) {
	var mapData map[string]interface{}
	if err := json.Unmarshal([]byte(jsonData), &mapData); err != nil {
		return mapData, err
	}
	return mapData, nil
}
